package com.itheima.controller;

import com.itheima.pojo.*;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Slf4j
@RestController

public class LoginController {

    @Autowired
    private EmpService empService;
    @PostMapping("/login")
    public Result login (@RequestBody Emp emp) {
        log.info("员工登录：{}", emp);
        LoginInfo loginInfo = empService.login(emp);//登录成功返回登录信息对象，登录失败返回null
        if (loginInfo != null) {
            return Result.success(loginInfo);
        }
        return Result.error("用户名或密码错误");
    }

    @GetMapping("/log/page")
    public Result logPage(@RequestParam(defaultValue = "1")Integer page,
                          @RequestParam(defaultValue = "10")Integer pageSize,
                          String operateEmpName, String className,String methodName,Long costTime,String methodParams, String returnValue,
                          @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDateTime openDateTime){
        log.info("分页查询日志信息，参数：page={},pageSize={},operateEmpName={},className={},methodName={},costTime={},methodParams={},returnValue={},openDateTime={}",
                page,pageSize,operateEmpName,className,methodName,costTime,methodParams,returnValue,openDateTime);
        PageResult pageResult = empService.logPage(page,pageSize,operateEmpName,className,methodName,costTime,methodParams,returnValue,openDateTime);
        return Result.success(pageResult);//返回分页查询结果
    }
}
